package com.nosnow.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author by bingHeng
 * @version 1.0
 * @Create 2020/3/29 23:40
 *
 * 自动填充类
 */

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    // 新增数据时，自动填充的字段
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("gmtCreate", new Date(), metaObject);
        this.setFieldValByName("gmtModified", new Date(), metaObject);
    }

    // 修改数据时，自动填充的字段
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified", new Date(), metaObject);
    }
}
